/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wanhai.itm.util;

import com.wanhai.bizbean.WHL_BizLocal;
import com.wanhai.data.tool.DataSet;
import com.wanhai.util.EjbClient;
import java.util.ArrayList;

/**
 *
 * @author m2434
 */
public class DataSetService {
    private WHL_BizLocal bizLocal;
    String strJNDIName = "java:/OraWhl2DS";
    
    public DataSetService(){
            initConn();
    }
    
    private void initConn(){
        try{
            if (bizLocal == null) {
                bizLocal = getEJBLocalRef(WHL_BizLocal.class, "WHL_BizBeanLocal");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        
        this.setBizLocal(bizLocal);
    }

    public WHL_BizLocal getBizLocal() {
        return bizLocal;
    }

    private void setBizLocal(WHL_BizLocal bizLocal) {
        this.bizLocal = bizLocal;
    }
    
    public DataSet getMISCData(String sql, ArrayList condList) throws Exception{
        return this.getBizLocal().getMISCData(sql, condList, strJNDIName);
    }
    
    public ArrayList callSFP(String mode, String SFP_name, ArrayList parameter) throws Exception{
        return this.getBizLocal().callSFP(mode, SFP_name, parameter, strJNDIName);
    }
    
    /**
     * get EJB Local instance by specified jndi name
     *
     * @param <T>
     * @param m_EJBLocalClz
     * @param m_JNDIName
     * @return
     * @throws Exception
     */
    private <T> T getEJBLocalRef(Class<T> m_EJBLocalClz, String m_JNDIName) throws Exception {
        Object ejbLocalHome = EjbClient.getEjbLocal(m_JNDIName);
        Object ejbLocal = ejbLocalHome.getClass().getMethod("create").invoke(ejbLocalHome);
        return (T) ejbLocal;
    }
}
